package com.wsmhz.web.config;

import com.wsmhz.web.fitter.ApiTimeFilter;
import com.wsmhz.web.interceptor.ApiTimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * create by tangbj on 2018/3/25
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private ApiTimeInterceptor apiTimeInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
		//registry.addInterceptor(apiTimeInterceptor);//每个API都会处理的时间拦截器
    }

    /**
     * 每个API都会处理的时间过滤器
     */
//    @Bean
//    public FilterRegistrationBean apiTimeFilter() {
//
//        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
//
//        ApiTimeFilter timeFilter = new ApiTimeFilter();
//        registrationBean.setFilter(timeFilter);
//        List<String> urls = new ArrayList<>();
//        urls.add("/*");  //自定义路径过滤
//        registrationBean.setUrlPatterns(urls);
//
//        return registrationBean;
//    }
}
